//
//  NetworkTool.m
//  AFNPackage
//
//  Created by Zhu Jinxin on 16/7/21.
//  Copyright © 2016年 Zhu Jinxin. All rights reserved.
//

#import "NetworkTool.h"

@implementation NetworkTool

+ (instancetype)sharedTools{
    
    static NetworkTool* networkTool;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        networkTool = [NetworkTool manager];
        networkTool.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", nil];
        
    });
    
    return networkTool;
    
}

- (void)requestWith:(requestType)type urlString:(NSString *)urlString parameters:(id)parameters success:(void (^)(id))successBlock failure:(void (^)(NSError *))failureBlock{
    
    if (type == GET) {
        
        [self GET:urlString parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
            
            successBlock(responseObject);
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
            failureBlock(error);
            
        }];
        

    }else if(type == POST){
        
        [self POST:urlString parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
            
            successBlock(responseObject);
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
            failureBlock(error);
            
        }];

        
    }else{
        
        printf("您的请求方法不合规范");
        
    }
    
    
    
    
    
}



@end
